<?php


namespace app\api\controller;

use app\admin\controller\UserFood;
use app\api\model\InfoTypeModel;
use app\api\model\InfoTypeRecord;
use app\api\model\UserAdviseDataModel;
use app\api\model\UserAdviseModel;
use app\api\model\UserFoodAttrModel;
use app\api\model\UserFoodModel;
use app\api\model\UserInfoModel;
use app\api\model\UserSportModel;
use app\api\model\UserTypeModel;
use app\common\controller\Api;

class RecordData extends Api
{

    protected $noNeedLogin = ['typeList'];
    protected $noNeedRight = ['*'];

    protected $day = [
        '99' => '全部',
        '2' => '摄入量',
        '3' => '热量',
        '4' => '血压',
        '5' => '饮水',
        '7' => '心率',
        '6' => '步数',
        '8' => '运动时间',
        '10' => '卡路里',
        '11' => '运动距离',
        '12' => '睡眠时长'
    ];

    protected $week = [
        '99' => '全部',
        '13' => '入睡时间',
        '1' => '睡眠时间',
        '3' => '血压',
        '4' => '血氧',
        '5' => '运动步数',
        '6' => '总饮水量',
        '7' => '大便次数',
        '8' => '摄入总热量',
        '9' => '总蛋白质',
        '10' => '总脂肪',
        '11' => '总膳食纤维',
        '12' => '总碳水化合物'
    ];


    /*
     * 获取数据统计列表
     */
    public function typeList()
    {
//        $list = InfoTypeModel::where(['is_show' => 1, 'is_count' => 1])->order('weigh desc')->select();

        $data = [
            'day' => $this->day,
            'week' => $this->week
        ];
        $this->success('请求成功', $data);
    }

    /*
     * 日数据统计
     */
    public function dayRecord()
    {

        $day = input('post.day', date('Y-m-d', time()));

        $type = input('post.type');

        $data = [];

        //三餐食物热量比
        $foodModel = new UserFoodModel();

        $zao = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id, 'type' => 1])->value('hot');
        $zhong = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id, 'type' => 2])->value('hot');
        $wan = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id, 'type' => 3])->value('hot');
        $sum_san_hot = $zao + $zhong + $wan;

        $userTypeModel = new UserTypeModel();
        $userType = $userTypeModel::get(['pid' => 13, 'type' => 0]);
        $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);
        $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '热量比';

        if ($sum_san_hot > 0) {
            $zao_b = number_format($zao / $sum_san_hot, 2) * 100;
            $zhong_b = number_format($zhong / $sum_san_hot, 2) * 100;
            $wan_b = number_format($wan / $sum_san_hot, 2) * 100;
            $data[] = [
                'data' => [
                    'series' => [
                        [
                            'data' => [
                                [
                                    'name' => '早餐',
                                    'value' => $zao_b
                                ],
                                [
                                    'name' => '午餐',
                                    'value' => $zhong_b
                                ],
                                [
                                    'name' => '晚餐',
                                    'value' => $wan_b
                                ]
                            ]
                        ]
                    ],
                    'title' => '三餐食物热量比（' . $text . ')',
                    'type' => 'pie',
                    'sign' => 'shiwurgdsfgdfshsd'
                ],

            ];
        } else {
            $data[] = [
                'sign' => 0
            ];
        }


        //三大产能营养比例
        //脂肪
        $s_fat = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id])->sum('fat');
        //碳水化合物
        $s_water = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id])->sum('water');
        //蛋白质
        $s_protein = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id])->sum('protein');

        $s_fat_c = $s_fat * 9;
        $s_protein_c = $s_protein * 4;
        $s_water_c = $s_water * 4;

        $sum_san_ying = $s_fat_c + $s_protein_c + $s_water_c;

        $userType = $userTypeModel::get(['pid' => 14, 'type' => 0]);

        $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

        $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '营养比例';

        if ($sum_san_ying > 0) {
            $fat_b = number_format($s_fat_c / $sum_san_ying, 2) * 100;
            $water_b = number_format($s_water_c / $sum_san_ying, 2) * 100;
            $protein_b = number_format($s_protein_c / $sum_san_ying, 2) * 100;
            $data[] = [
                'data' => [
                    'series' => [
                        [
                            'data' => [
                                [
                                    'name' => '碳水化合物',
                                    'value' => $water_b
                                ],
                                [
                                    'name' => '脂肪',
                                    'value' => $fat_b
                                ],
                                [
                                    'name' => '蛋白质',
                                    'value' => $protein_b
                                ]
                            ]
                        ]
                    ],
                    'title' => '三大产能营养比例（' . $text . ')',
                    'type' => 'pie',
                    'sign' => 'yingyangrgdsfgdfshsd'
                ]
            ];
        } else {
            $data[] = [
                'sign' => 0
            ];
        }

        //
        $userInfoModel = new UserInfoModel();
        if (empty($type)) {
            $search = $this->day;
        } else {
            $search_arr = explode(',', $type);
            $search = [];
            $day_s = $this->day;
            foreach ($search_arr as $key => $val) {
                if ($val == 99) {
                    $search = $this->day;
                }
                $search[$key] = $day_s[$val];
            }
        }

//        var_dump($search);die;
//        $typeList = InfoTypeModel::all(['id' => ['in', $type]]);
//var_dump($search);die;
        $recordModel = new InfoTypeRecord();
        $userAdviseData = new UserAdviseDataModel();
        foreach ($search as $val) {

            switch ($val) {
                case '摄入量':
                    //总膳食纤维
                    $s_dietary = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id])->sum('dietary');

                    $userType = $userTypeModel::get(['pid' => 2, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '数据来自饮食打卡';

                    //总碳水(参考)
                    $c_water_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 1]);
                    $c_water = !empty($c_water_info['num']) ? $c_water_info['num'] : 10;
                    //总脂肪(参考)
                    $c_water_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 2]);
                    $c_zhifang = !empty($c_water_info['num']) ? $c_water_info['num'] : 20;
                    //总蛋白质(参考)
                    $c_water_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 3]);
                    $c_danbai = !empty($c_water_info['num']) ? $c_water_info['num'] : 10;
                    //总膳食纤维(参考)
                    $c_water_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 4]);
                    $c_qianwei = !empty($c_water_info['num']) ? $c_water_info['num'] : 10;

                    $c_water = empty($s_water) ? 0 : $c_water;
                    $c_zhifang = empty($s_fat) ? 0 : $c_zhifang;
                    $c_danbai = empty($s_protein) ? 0 : $c_danbai;
                    $c_qianwei = empty($s_dietary) ? 0 : $c_qianwei;

                    $data[] = [
                        'data' => [
                            'categories' => [
                                '总碳水',//碳水
                                '总脂肪',//脂肪
                                '总蛋白质',//蛋白质
                                '总膳食纤维'//膳食纤维
                            ],
                            'series' => [
                                [
                                    'name' => '标准值',
                                    'data' => [
                                        round($c_water, 2), round($c_zhifang, 2), round($c_danbai, 2), round($c_qianwei, 2)
                                    ]
                                ],
                                [
                                    'name' => '摄入量',
                                    'data' => [round($s_water, 2), round($s_fat, 2), round($s_protein, 2), round($s_dietary, 2)]
                                ]
                            ]
                        ],
                        'title' => $val . '(g)',
                        'advice' => $text,
                        'sign' => 'yinshirgdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;

                case '热量':
                    $s_hot = $foodModel::where(['day' => $day, 'user_id' => $this->auth->id])->sum('hot');
                    $userType = $userTypeModel::get(['pid' => 3, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '成人轻度体力劳动：2100-2400千卡；成人中度体力劳动：2300-2700千卡；成人重度体力劳动：2700-3200千卡';
                    //标准热量(参考)
                    $c_hot_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 5]);
                    $c_hot = !empty($c_hot_info['num']) ? $c_hot_info['num'] : 10;

                    $data[] = [
                        'data' => [
                            'categories' => [
//                                '总热量',
                                '热量',
                                '标准热量'
                            ],
                            'series' => [
                                [
                                    'name' => '热量',
                                    'data' => [round($s_hot, 2),$c_hot]
                                ]
                            ]
                        ],
                        'title' => $val . '(kcal)',
                        'advice' => $text,
                        'type' => 'column',
                        'sign' => 'hotrgdsfgdfshsd',
                    ];
                    break;
                case '饮水':
                    //原来的逻辑 这是碳水合物的修改
                    //$s_water = UserFoodModel::where(['type' => 5, 'user_id' => $this->auth->id, 'day' => $day])->sum('water');
                    $water = \app\admin\model\UserFood::where(['day' => $day, 'user_id' => $this->auth->id, 'type' => 5])->column('id');
                    $water_zong = UserFoodAttrModel::where('pid', 'in', $water)->sum('food_value');

                    $userType = $userTypeModel::get(['pid' => 5, 'type' => 0]);
                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);
                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '参考标准范围：1500-2500毫升';
                    //标准饮水(参考)
                    $c_water_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 10]);
                    $c_water = !empty($c_water_info['num']) ? $c_water_info['num'] : 1500;
                    $data[] = [
                        'data' => [
                            'categories' => [
                                '最低饮水',
                                '总饮水',
                                '最高饮水'
                            ],
                            'series' => [
                                [
                                    'name' => '饮水',
                                    //'data' => [$s_water, 450],
                                    'data' => [1500,$water_zong,2500]
                                ]
                            ]
                        ],
                        'title' => $val . '(ML)',
                        'advice' => $text,
                        'sign' => 'yinshuirgdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;
                case '步数':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 17])->order('taketime asc')->select();
                    $categories = [];
                    $series = [];
                    $b_g = [];
                    $b_d = [];
                    $bushu = 0;
                    foreach ($juliDetail as $v) {
                        if (!empty($v['type_value'])) {
                            $bushu += $v['type_value'];
                            $categories[] = date('H:i', $v['taketime']);
                            $series[] = $bushu;
                            $b_g[] = 10000;
                            $b_d[] = 6000;
                        }
                    }


                    $userType = $userTypeModel::get(['pid' => 6, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '参考标准范围：6000-10000步';
//                    var_dump($bushuDetail['type_value']);die;
                    $data[] = [
                        'data' => [
                            'categories' => ['标准（最低）','步数','标准（最高）'],
                            'series' => [
                                [
                                    'name' => '步数',
                                    'data' => [6000,$bushu,10000]
                                ]
                            ]
                        ],
                        'title' => $val . '(步/天)',
                        'advice' => $text,
                        'sign' => 'bushurgdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;
                case '运动时间':
                    //$juliDetail = $recordModel->get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 13]);
                    $juliDetail = UserSportModel::where(["user_id" => $this->auth->id, "day" => $day])->where('dakatime is not null')->field('endtime,starttime')->select();
                    $type_value = 0;
                    if (count($juliDetail) > 0) {
                        foreach ($juliDetail as $value) {
                            $time = ceil(($value['endtime'] - $value['starttime']) / 60);
                            $type_value += $time;
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 8, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '参考标准范围：30-60分钟';
                    //标准饮水(参考)
                    $c_time_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 15]);
                    $c_time = !empty($c_time_info['num']) ? $c_time_info['num'] : 3000;
                    $data[] = ['data' => [
                        'categories' => [
                            '最低时间',
                            '实际时间',
                            '最高时间'
                        ],
                        'series' => [
                            [
                                'name' => '时间',
                                'data' => [30,$type_value,60]
                            ]
                        ]
                    ],
                        'title' => $val . '(min)',
                        'advice' => $text,
                        'sign' => 'sporttimergdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;
                case '心率':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 6])->order('taketime asc')->select();
                    $categories = [];
                    $series = [];
                    $series_g = [];
                    $series_d = [];
                    foreach ($juliDetail as $v) {
                        if (!empty($v['type_value'])) {
                            $categories[] = date('H:i', $v['taketime']);
                            $series[] = $v['type_value'];
                            $series_g[] = 100;
                            $series_d[] = 60;
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 7, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '运动健康心率：（170-年龄）次/分钟';

                    $data[] = [
                        'data' => [
                            'categories' => $categories,
                            'series' => [
                                [
                                    'name' => '心率',
                                    'data' => $series
                                ],
                                [
                                    'name' => '标准心率(最高)',
                                    'data' => $series_g
                                ],
                                [
                                    'name' => '标准心率(最低)',
                                    'data' => $series_d
                                ]
                            ]
                        ],
                        'title' => $val . '(次/分)',
                        'advice' => $text,
                        'sign' => 'xinlvrgdsfgdfshsd',
                        'type' => 'line'
                    ];
                    break;
                case '卡路里':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 24])->order('taketime asc')->select();
                    $categories = [];
                    $series = [];
                    $ka = 0;
                    foreach ($juliDetail as $v) {
                        if (!empty($v['type_value'])) {
                            $ka += $v['type_value'];
                            $ka = number_format($ka, 2);
                            $categories[] = date('H:i', $v['taketime']);
                            $series[] = $ka;

                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 10, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '成人轻度体力劳动：2100-2400千卡；成人中度体力劳动：2300-2700千卡；成人重度体力劳动：2700-3200千卡';
                    $data[] = [
                        'data' => [
                            'categories' => $categories,
                            'series' => [
                                [
                                    'name' => '千卡',
                                    'data' => $series
                                ]
                            ]
                        ],
                        'title' => $val . '(千卡)',
                        'advice' => $text,
                        'sign' => 'lalulirgdsfgdfshsd',
                        'type' => 'line'
                    ];
                    break;
                case '运动距离':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 12])->sum('type_value');

                    $series = number_format($juliDetail, 2);
                    $userType = $userTypeModel::get(['pid' => 11, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '参考标准范围:≥3公里/日';
                    $data[] = [
                        'data' => [
                            'categories' => ['运动距离','标准距离'],
                            'series' => [
                                [
                                    'name' => '运动距离',
                                    'data' => [$series,3]
                                ]
                            ]
                        ],
                        'title' => $val . '(公里)',
                        'advice' => $text,
                        'sign' => 'yundognjulirgdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;
                case '血压':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 21])->order('taketime asc')->select();

                    if (!empty($juliDetail)) {
//
//                        while (count($juliDetail) > 12 ) {
//                            foreach ($juliDetail as $key => $v) {
//                                if($key%2==0){
//                                    unset($juliDetail[$key]);
//                                }
//                            }
//                        }

                        foreach ($juliDetail as $v) {
                            $v_str = explode(',', $v['type_value']);
                            $tim[] = date('H:i', $v['taketime']);
                            $gao[] = $v_str[1];
                            $di[] =  $v_str[0];
                            $gao_g[] = 139;
                            $gao_d[] = 90;
                            $di_g[] = 89;
                            $di_d[] = 60;
                        }
                    } else {
                        $tim = [0, 3, 6, 9, 12, 15, 18, 21, 24];
                        $di = [0, 0, 0, 0, 0, 0, 0, 0, 0];
                        $gao = [0, 0, 0, 0, 0, 0, 0, 0, 0];
                        $gao_g = [139, 139, 139, 139, 139, 139, 139, 139, 139];
                        $gao_d = [90, 90, 90, 90, 90, 90, 90, 90, 90];
                        $di_g = [89, 89, 89, 89, 89, 89, 89, 89, 89];
                        $di_d = [60, 60, 60, 60, 60, 60, 60, 60, 60];
                    }

                    $userType = $userTypeModel::get(['pid' => 4, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '成人：收缩压90～139mmHg和舒张压60～89mmHg';

                    $data[] = [
                        'data' => [
                            'categories' => $tim,
                            'series' => [
                                [
                                    'name' => '收缩压',
                                    'data' => $gao
                                ],
                                [
                                    'name' => '舒张压',
                                    'data' => $di
                                ],
                                [
                                    'name' => '收缩压(最高值)',
                                    'data' =>
                                        $gao_g,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '收缩压(最低值)',
                                    'data' =>
                                        $gao_d,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '舒张压(最高值)',
                                    'data' =>
                                        $di_g,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '舒张压(最低值)',
                                    'data' =>
                                        $di_d,
                                    'type' => 'line'
                                ]
                            ]
                        ],
                        'title' => $val . '(mmHg)',
                        'advice' => $text,
                        'sign' => 'xueyargdsfgdfshsd',
                        'type' => 'line'
                    ];
                    break;
                case '睡眠时长':
                    $juliDetail = $recordModel->where(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 17])->order('taketime asc')->select();
                    $categories = [];
                    $ruArr = [];
                    $qianArr = [];
                    $shenArr = [];
                    $qingArr = [];
                    $ru_num = 0;
                    $qian_num = 0;
                    $shen_num = 0;
                    $qing_num = 0;
                    foreach ($juliDetail as $k => $v) {
                        $check = 0;
                        //入睡时间
                        $ruDetail = $recordModel::get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 14, 'taketime' => $v['taketime']]);
                        if (!$ruDetail) {
                            $ruArr[] = 0;
                        } else {
                            $ruArr[] = 10;
                            $ru_num += 10;
                            $check++;
                        }
                        //浅睡时间
                        $qianDetail = $recordModel::get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 18, 'taketime' => $v['taketime']]);
                        if (!$qianDetail) {
                            $qianArr[] = 0;
                        } else {
                            $qianArr[] = 10;
                            $qian_num += 10;
                            $check++;
                        }
                        //深睡时间
                        $shenDetail = $recordModel::get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 19, 'taketime' => $v['taketime']]);
                        if (!$shenDetail) {
                            $shenArr[] = 0;
                        } else {
                            $shenArr[] = 10;
                            $shen_num += 10;
                            $check++;
                        }
                        //清醒睡眠
                        $qingDetail = $recordModel::get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => 16, 'taketime' => $v['taketime']]);
                        if (!$qingDetail) {
                            $qingArr[] = 0;
                        } else {
                            $qingArr[] = 10;
                            $qing_num += 10;
                            $check++;
                        }
                        if ($check == 0) {
                            unset($ruArr[$k]);
                            unset($qianArr[$k]);
                            unset($shenArr[$k]);
                            unset($qingArr[$k]);
                            $checkDetail = $recordModel::get(['user_id' => $this->auth->id, 'day' => $day, 'type_id' => ['in', [14, 16, 18, 19]], 'taketime' => ['>', $v['taketime']]]);
                            if (!$checkDetail) {
                                break;
                            }
                        } else {
                            $categories[] = date('H:i', $v['taketime']);
                        }
                    }
                    $ruArr = array_values($ruArr);
                    $qianArr = array_values($qianArr);
                    $shenArr = array_values($shenArr);
                    $qingArr = array_values($qingArr);
                    if ($ru_num > 0) {
                        $ru_h = sprintf("%.1f", ($ru_num / 60));
                    } else {
                        $ru_h = 0;
                    }

                    if ($qian_num > 0) {
                        $qian_h = sprintf("%.1f", ($qian_num / 60));
                    } else {
                        $qian_h = 0;
                    }

                    if ($shen_num > 0) {
                        $shen_h = sprintf("%.1f", ($shen_num / 60));
                    } else {
                        $shen_h = 0;
                    }

                    if ($qing_num > 0) {
                        $qing_h = sprintf("%.1f", ($qing_num / 60));
                    } else {
                        $qing_h = 0;
                    }
                    $userType = $userTypeModel::get(['pid' => 12, 'type' => 0]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '标准范围：7-8小时（正常成人)';

                    $data[] = [
                        'data' => [
                            'categories' => ['开始入睡','浅睡','深睡','清醒睡眠'],
                            'series' => [
                                [
                                    'name' => '时间',
                                    //'data' => [$s_water, 450],
                                    'data' => [$ru_h,$qian_h,$shen_h,$qing_h]
                                ],
//                                [
//                                    'name' => '开始入睡(' . $ru_h . ')',
//                                    //'data' => [$s_water, 450],
//                                    'data' => $ruArr
//                                ],
//                                [
//                                    'name' => '浅睡(' . $qian_h . ')',
//                                    //'data' => [$s_water, 450],
//                                    'data' => $qianArr
//                                ],
//                                [
//                                    'name' => '深睡(' . $shen_h . ')',
//                                    //'data' => [$s_water, 450],
//                                    'data' => $shenArr
//                                ],
//                                [
//                                    'name' => '清醒睡眠(' . $qing_h . ')',
//                                    //'data' => [$s_water, 450],
//                                    'data' => $qingArr
//                                ],
                            ]
                        ],
                        'title' => $val . '(h)',
                        'advice' => $text,
                        'sign' => 'shuimianrgdsfgdfshsd',
                        'type' => 'column'
                    ];
                    break;
            }
        }

        $this->success('请求成功', $data);

    }

    /**
     * 周统计
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function weekRecord()
    {
        $day = input('post.day', date('Y-m-d', time()));

        $type = input('post.type');

        $data = [];

        $day = strtotime($day);

        $week = $this->get_week($day);

        $weekNameArr = [];
        $weekTimeArr = [];
        foreach ($week as $val) {
            $weekNameArr[] = $val['week'];
            $weekTimeArr[] = $val['date'];
        }

        if (empty($type)) {
            $search = $this->week;
        } else {
            $search_arr = explode(',', $type);
            $search = [];
            $day = $this->week;
            foreach ($search_arr as $key => $val) {
                if ($val == 99) {
                    $search = $this->week;
                }
                $search[$key] = $day[$val];
            }
        }
        $recordModel = new InfoTypeRecord();
        $userTypeModel = new UserTypeModel();
        $userAdviseData = new UserAdviseDataModel();

        foreach ($search as $val) {
            switch ($val) {
                case '入睡时间':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = $recordModel->where(['type_id' => 14, 'user_id' => $this->auth->id, 'day' => $item])->count();
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = $detail * 10;
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 13, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '30min内入睡（正常成人）';

                    //标准饮水(参考)
                    $c_sleep_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 16]);
                    $c_sleep_d = !empty($c_sleep_info['num']) ? $c_sleep_info['num'] : 25;
                    $c_sleep_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 14]);
                    $c_sleep_g = !empty($c_sleep_info['num']) ? $c_sleep_info['num'] : 30;

                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '标准线最高值',
                                    'data' =>
                                        [$c_sleep_g, $c_sleep_g, $c_sleep_g, $c_sleep_g, $c_sleep_g, $c_sleep_g, $c_sleep_g]
                                ],
                                [
                                    'name' => '均值',
                                    'data' =>
                                        $detail_list
                                ],
                                [
                                    'name' => '标准线最低值',
                                    'data' =>
                                        [$c_sleep_d, $c_sleep_d, $c_sleep_d, $c_sleep_d, $c_sleep_d, $c_sleep_d, $c_sleep_d]
                                ],
                            ]
                        ],
                        'title' => $val . '(min)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'rushuirgdsfgdfshsd'
                    ];
                    break;
                case '睡眠时间':
                    foreach ($weekTimeArr as $item) {
                        //入睡时间
                        $ru_detail = $recordModel->where(['type_id' => 14, 'user_id' => $this->auth->id, 'day' => $item])->count();
                        //清醒时间
                        $qing_detail = $recordModel->where(['type_id' => 16, 'user_id' => $this->auth->id, 'day' => $item])->count();
                        //浅睡
                        $qian_detail = $recordModel->where(['type_id' => 18, 'user_id' => $this->auth->id, 'day' => $item])->count();
                        //深睡
                        $shen_detail = $recordModel->where(['type_id' => 19, 'user_id' => $this->auth->id, 'day' => $item])->count();
                        if (empty($ru_detail)) {
                            $ru_list[] = 0;
                        } else {
                            $ru_list[] = sprintf("%.1f", $ru_detail * 10 / 60);
                        }
                        if (empty($qing_detail)) {
                            $qing_list[] = 0;
                        } else {
                            $qing_list[] = sprintf("%.1f", $qing_detail * 10 / 60);
                        }
                        if (empty($qian_detail)) {
                            $qian_list[] = 0;
                        } else {
                            $qian_list[] = sprintf("%.1f", $qian_detail * 10 / 60);
                        }
                        if (empty($shen_detail)) {
                            $shen_list[] = 0;
                        } else {
                            $shen_list[] = sprintf("%.1f", $shen_detail * 10 / 60);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 1, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '7-8小时（正常成人）';
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '入睡时间',
                                    'data' => $ru_list
                                ],
                                [
                                    'name' => '清醒时间',
                                    'data' => $qing_list
                                ],
                                [
                                    'name' => '浅睡眠时间',
                                    'data' => $qian_list
                                ],
                                [
                                    'name' => '深睡时间',
                                    'data' => $shen_list
                                ]
                            ]
                        ],
                        'title' => $val . '(h)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'shuimianrgdsfgdfshsd',
                    ];
                    break;

                case '血压':
                    $d_list = [];
                    $g_list = [];
                    $gao_g = [];
                    $gao_d = [];
                    $di_g = [];
                    $di_d = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = $recordModel->where(['type_id' => 21, 'user_id' => $this->auth->id, 'day' => $item])->select();

                        if (empty($detail)) {
                            $d_list[] = 0;
                            $g_list[] = 0;
                        } else {
                            $d_num = count($detail);
                            $d = 0;
                            $g = 0;
                            foreach ($detail as $v) {
                                $v_arr = explode(',', $v['type_value']);
                                $d += $v_arr[0];
                                $g += $v_arr[1];
                            }
                            $d = $d / $d_num;
                            $g = $g / $d_num;
                            $d_list[] = sprintf("%.0f", $d);
                            $g_list[] = sprintf("%.0f", $g);

                        }

                        $gao_g[] = 139;
                        $gao_d[] = 90;
                        $di_g[] = 89;
                        $di_d[] = 60;
                    }

                    $userType = $userTypeModel::get(['pid' => 3, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '正常低压60，高压120';

                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '舒张压',
                                    'data' => $d_list
                                ],
                                [
                                    'name' => '收缩压',
                                    'data' => $g_list
                                ],
                                [
                                    'name' => '收缩压(最高值)',
                                    'data' =>
                                        $gao_g,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '收缩压(最低值)',
                                    'data' =>
                                        $gao_d,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '舒张压(最高值)',
                                    'data' =>
                                        $di_g,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '舒张压(最低值)',
                                    'data' =>
                                        $di_d,
                                    'type' => 'line'
                                ]
                            ]
                        ],
                        'title' => $val . '(mmHg)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'xueyargdsfgdfshsd',
                    ];
                    break;

                case '血氧':
                    $detail_list = [];
                    $detail_g = [];
                    $detail_d = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = $recordModel->where(['type_id' => 7, 'user_id' => $this->auth->id, 'day' => $item])->select();
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $d = 0;
                            $d_num = count($detail);
                            foreach ($detail as $v) {
                                $d += $v['type_value'];
                            }
                            $d = $d / $d_num;
                            $detail_list[] = sprintf("%.2f", $d);
                        }
                        $detail_g[] = 100;
                        $detail_d[] = 95;
                    }
                    $userType = $userTypeModel::get(['pid' => 4, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '95-100%（正常成人）';
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '血氧值',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '标准(高)',
                                    'data' => $detail_g
                                ],
                                [
                                    'name' => '标准(低)',
                                    'data' => $detail_d
                                ]
                            ]
                        ],
                        'title' => $val . '(%)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'xueyangrgdsfgdfshsd',
                    ];
                    break;

                case '运动步数':
                    $detail_list = [];
                    $b_g = [];
                    $b_d = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = $recordModel->where(['type_id' => 17, 'user_id' => $this->auth->id, 'day' => $item])->sum('type_value');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = $detail;
                        }
                        $b_g[] = 10000;
                        $b_d[] = 6000;
                    }
                    $userType = $userTypeModel::get(['pid' => 5, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '数据来自蓝牙手环';
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '运动步数',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '标准（最高）',
                                    'data' =>
                                        $b_g,
                                    'type' => 'line'
                                ],
                                [
                                    'name' => '标准（最低）',
                                    'data' =>
                                        $b_d,
                                    'type' => 'line'
                                ]
                            ]
                        ],
                        'title' => $val . '(步)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'bushurgdsfgdfshsd',
                    ];
                    break;
                case '总饮水量':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        //$detail = UserFoodModel::where(['type' => 5, 'user_id' => $this->auth->id, 'day' => $item])->sum('water');
                        $water = \app\admin\model\UserFood::where(['day' => $item, 'user_id' => $this->auth->id, 'type' => 5])->column('id');
                        $detail = UserFoodAttrModel::where('pid', 'in', $water)->sum('food_value');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = $detail;
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 6, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '推荐1500-2500ml/d（正常成人）';
                    //标准饮水
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 23]);
                    $c_drink = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 500;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总饮水量',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '标准饮水量',
                                    'data' =>
                                        [$c_drink, $c_drink, $c_drink, $c_drink, $c_drink, $c_drink, $c_drink],
                                    'type' => 'line'
                                ]
                            ]
                        ],
                        'title' => $val . '(ml)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'yinshuirgdsfgdfshsd',
                    ];
                    break;
                case '大便次数':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {

                        $detail = $recordModel->where(['type_id' => 22, 'user_id' => $this->auth->id, 'day' => $item])->value('type_value');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = $detail;
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 7, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '1-2次/d或1次/2d（正常成人）';

                    //标准饮水
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 17]);
                    $c_drink = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 1;

                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '大便次数',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '标准次数',
                                    'data' =>
                                        [$c_drink, $c_drink, $c_drink, $c_drink, $c_drink, $c_drink, $c_drink],
                                    'type' => 'line'
                                ]
                            ]
                        ],
                        'title' => $val . '(次)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'dabianrgdsfgdfshsd',
                    ];
                    break;
                case '摄入总热量':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = UserFoodModel::where(['user_id' => $this->auth->id, 'day' => $item])->sum('hot');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = round($detail, 2);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 8, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '成人轻度体力劳动:2100-2400千卡；成人中度体力劳动:2300-2700千卡;成人重度体力劳动:2700-3200千卡';
                    //标准总热量
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 18]);
                    $c_drink_d = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 2100;
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 24]);
                    $c_drink_g = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 2400;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总热量',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '总热量(高)',
                                    'data' =>
                                        [$c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g],
                                ],
                                [
                                    'name' => '总热量(低)',
                                    'data' =>
                                        [$c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d],
                                ]
                            ]
                        ],
                        'title' => $val . '(kcal)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'hotrgdsfgdfshsd',
                    ];
                    break;
                case '总蛋白质':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = UserFoodModel::where(['user_id' => $this->auth->id, 'day' => $item])->sum('protein');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = round($detail, 2);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 9, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '占摄入总热量的10-15%/d（正常成人）';

                    //标准蛋白质
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 19]);
                    $c_drink_d = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 2;
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 25]);
                    $c_drink_g = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 5;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总蛋白质',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '总蛋白质(高)',
                                    'data' =>
                                        [$c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g]
                                ],
                                [
                                    'name' => '总蛋白质(低)',
                                    'data' =>
                                        [$c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d]
                                ]
                            ]
                        ],
                        'title' => $val . '(g)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'danbairgdsfgdfshsd',
                    ];
                    break;
                case '总脂肪':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = UserFoodModel::where(['user_id' => $this->auth->id, 'day' => $item])->sum('fat');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = round($detail, 2);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 10, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '占摄入总热量的20-25%/d（正常成人）';
                    //标准脂肪
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 20]);
                    $c_drink_d = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 12;
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 26]);
                    $c_drink_g = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 18;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总脂肪',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '总脂肪(高)',
                                    'data' =>
                                        [$c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g],
                                ],
                                [
                                    'name' => '总脂肪(低)',
                                    'data' =>
                                        [$c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d],
                                ]
                            ]
                        ],
                        'title' => $val . '(g)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'zhifangrgdsfgdfshsd',
                    ];
                    break;
                case '总膳食纤维':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = UserFoodModel::where(['user_id' => $this->auth->id, 'day' => $item])->sum('dietary');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = round($detail, 2);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 11, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '25-30g/d（正常成人）';
                    //标准膳食纤维
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 21]);
                    $c_drink_d = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 12;
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 27]);
                    $c_drink_g = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 18;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总膳食纤维',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '总膳食纤维(高)',
                                    'data' =>
                                        [$c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g],
                                ],
                                [
                                    'name' => '总膳食纤维(低)',
                                    'data' =>
                                        [$c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d],
                                ]
                            ]
                        ],
                        'title' => $val . '(g)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'shanshirgdsfgdfshsd',
                    ];
                    break;
                case '总碳水化合物':
                    $detail_list = [];
                    foreach ($weekTimeArr as $item) {
                        $detail = UserFoodModel::where(['user_id' => $this->auth->id, 'type' => ['NEQ', 5], 'day' => $item])->sum('water');
                        if (empty($detail)) {
                            $detail_list[] = 0;
                        } else {
                            $detail_list[] = round($detail, 2);
                        }
                    }
                    $userType = $userTypeModel::get(['pid' => 12, 'type' => 1]);

                    $userAdvise = UserAdviseModel::get(['user_id' => $this->auth->id, 'type_id' => $userType['id']]);

                    $text = !empty($userAdvise['title']) ? $userAdvise['title'] : '占总热量的50-60%/d（正常成人）';
                    //标准碳水化合物
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 22]);
                    $c_drink_d = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 12;
                    $c_drink_info = $userAdviseData::get(['user_id' => $this->auth->id, 'type_id' => 28]);
                    $c_drink_g = !empty($c_drink_info['num']) ? $c_drink_info['num'] : 18;
                    $data[] = [
                        'data' => [
                            'categories' => $weekNameArr,
                            'series' => [
                                [
                                    'name' => '总碳水化合物',
                                    'data' => $detail_list
                                ],
                                [
                                    'name' => '总碳水化合物(高)',
                                    'data' =>
                                        [$c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g, $c_drink_g],
                                ],
                                [
                                    'name' => '总碳水化合物(低)',
                                    'data' =>
                                        [$c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d, $c_drink_d],
                                ]
                            ]
                        ],
                        'title' => $val . '(g)',
                        'advice' => $text,
                        'type' => 'line',
                        'sign' => 'tanshuirgdsfgdfshsd',
                    ];
                    break;
            }

        }
        $this->success('请求成功', $data);

    }

    /**
     *  * 获取一周日期
     *  * @param $time 时间戳
     *  * @param $format 转换格式
     *  */
    public function get_week($time, $format = "Y-m-d")
    {
        $week = date('w', $time);
        $weekname = array('星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日');
        if (empty($week)) {
            $week = 7;
        }
        for ($i = 0; $i <= 6; $i++) {
            $data[$i]['date'] = date($format, strtotime('+' . $i + 1 - $week . ' days', $time));
            $data[$i]['week'] = $weekname[$i];
        }
        return $data;
    }

}